# -*- mode:python -*-

# Copyright (c) 2011 Mark D. Hill and David A. Wood
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

Import('*')

import os

env.Command('instructions.h', 'instructions.cc', ['touch $TARGET',
	'chmod +w $TARGET',
	'echo "// DO NOT EDIT THIS FILE! IT IS AUTOMATICALLY GENERATED BY THE MAKEFILE (see target for instructions.h)" > $TARGET',
	'echo "#include "\\""ptx_ir.h\\"" >> $TARGET',
	'echo "#ifndef instructions_h_included" >> $TARGET',
	'echo "#define instructions_h_included" >> $TARGET',
	'cat $SOURCE | grep "_impl(" | sed \'s/{.*//\' | sed \'s/$$/;/\' >> $TARGET',
	'echo "#endif" >> $TARGET',
	'chmod -w $TARGET',
	'echo "created $TARGET"'])
env.Ignore("instructions.h", "instructions.h")

env1 = Environment(YACCFLAGS=' -d --name-prefix=ptx_')
env1.CFile(target = 'ptx.tab.c', source = 'ptx.y')
env1.CFile(target = 'lex.ptx_.c', source = 'ptx.l')

env2 = Environment(YACCFLAGS=' -d --name-prefix=ptxinfo_')
env2.CFile(target = 'ptxinfo.tab.c', source = 'ptxinfo.y')
env2.CFile(target = 'lex.ptxinfo_.c', source = 'ptxinfo.l')



Source('cuda_device_printf.cc', Werror=False)
Source('lex.ptx_.c', Werror=False)
Source('lex.ptxinfo_.c', Werror=False)
Source('ptx.tab.c', Werror=False)
Source('ptxinfo.tab.c', Werror=False)
Source('cuda-sim.cc', Werror=False)
Source('instructions.cc', Werror=False)
Source('memory.cc', Werror=False)
Source('ptx_ir.cc', Werror=False)
Source('ptx_loader.cc', Werror=False)
Source('ptx_parser.cc', Werror=False)
Source('ptx_sim.cc', Werror=False)
Source('ptx-stats.cc', Werror=False)
Source('decuda_pred_table/decuda_pred_table.cc', Werror=False)
